package com.bfxy.disruptor.heigh.multi;

import com.lmax.disruptor.RingBuffer;

public class Producer {
    // 有一个数据仓库
    private RingBuffer<Order> ringBuffer;

    public Producer(RingBuffer<Order> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void sendData(String uuid) {
        // 从这个仓库中获取一个空的产品，里面的属性没有值
        long sequence = ringBuffer.next();
        try {
            Order order = ringBuffer.get(sequence);
            // 往这个产品里面的属性赋值
            order.setId(uuid);
        } finally {
            // 仓库将这个产品发布出去
            ringBuffer.publish(sequence);
        }
    }

}
